package com.magenta.maxoptra.gis.distancematrix.commands;

import com.magenta.maxoptra.gis.GeoProviderSettings;
import com.magenta.maxoptra.gis.distancematrix.Command;
import com.magenta.maxoptra.gis.distancematrix.EventType;
import com.magenta.maxoptra.gis.distancematrix.MatrixCoordinates;

import java.util.List;
import java.util.Set;

/**
 * @author Sergey Grachev
 */
public final class CommandsFactory {

    private CommandsFactory() {
    }

    /**
     * Start updating for group
     */
    public static Command newStartGroup(final long groupId) {
        return new StartGroup(groupId);
    }

    /**
     * Stop any actions for group
     */
    public static Command newStopGroup(final long groupId) {
        return new StopGroup(groupId);
    }

    /**
     * Add new coordinates of matrices to the queue for updating
     */
    public static Command newAddCoordinates(final long groupId, final List<MatrixCoordinates> matrices) {
        return new AddCoordinates(groupId, matrices);
    }

    /**
     * Remove coordinates of matrices from updating
     */
    public static Command newRemoveCoordinates(final long groupId, final List<MatrixCoordinates> matrices) {
        return new RemoveCoordinates(groupId, matrices);
    }

    /**
     * Replace current coordinates of matrices with new and start updating if is necessary
     */
    public static Command newSynchronizeMatrices(final long groupId, final List<MatrixCoordinates> matrices) {
        return new SynchronizeMatrices(groupId, matrices);
    }

    /**
     * Change geo provider settings for group. If there is at least one coordinate of the previous update with another
     * provider, then all will be updated again with new geo provider
     */
    public static Command newChangeGeoProviderSettings(final long groupId, final GeoProviderSettings settings) {
        return new ChangeGeoProviderSettings(groupId, settings);
    }

    /**
     * Change delay between requests to geo provider
     */
    public static Command newChangeRequestsDelay(final long groupId, final int delay) {
        return new ChangeRequestsDelay(groupId, delay);
    }

    /**
     * Set time interval when matrix should be updated for concrete group
     *
     * @param from millis of day
     * @param to   millis of day
     */
    public static Command newChangeUpdateTimeInterval(final long groupId, final int from, final int to) {
        return new ChangeUpdateTimeInterval(groupId, from, to);
    }

    /**
     *
     * @param groupId
     * @param matrixId
     */
    public static Command newForceMatrixUpdate(final long groupId, final long matrixId) {
        return new ForceMatrixUpdate(groupId, matrixId);
    }

    /**
     * @param queueName
     * @param events
     */
    public static Command newEventsSubscribe(final String queueName, final Set<EventType> events) {
        return new EventsSubscribe(queueName, events);
    }

    /**
     * @param queueName
     * @param events
     */
    public static Command newEventsUnsubscribe(final String queueName, final Set<EventType> events) {
        return new EventsUnsubscribe(queueName, events);
    }
}
